/*
 * Copyright 2008 Nathan C Jones
 * 
 * This file is part of Fivehundred.
 * 
 * Fivehundred is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * 
 * Fivehundred is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * Fivehundred. If not, see <http://www.gnu.org/licenses/>. 
 */
package com.googlecode.fivehundred.model;

/**
 * A pair of players working together to get 500 points.
 * 
 * @author Nathan C Jones
 */
public class Team {

	/** The first player. */
	private final Player playerOne;

	/** The second player. */
	private final Player playerTwo;

	/** The team's current score. */
	private short score = 0;

	/**
	 * Create a new team with the two players.
	 * 
	 * @param playerOne the first player on the team.
	 * @param playerTwo the second player on the team.
	 */
	public Team(final Player playerOne, final Player playerTwo) {
		super();
		this.playerOne = playerOne;
		this.playerTwo = playerTwo;
	}

	/**
	 * @return the first player on the team.
	 */
	public Player getPlayerOne() {
		return playerOne;
	}

	/**
	 * @return the second player on the team.
	 */
	public Player getPlayerTwo() {
		return playerTwo;
	}

	/**
	 * @return the team's score.
	 */
	public short getScore() {
		return score;
	}

	/**
	 * Set the team's score.
	 * 
	 * @param score the new score.
	 */
	public void setScore(short score) {
		this.score = score;
	}

	/**
	 * Determine if the team has gone out of the game. A team is out if they
	 * have (explicitly) either won or lost. Explicitly winning or losing means
	 * the points criteria for winning or losing has been met. For example, even
	 * if a team is not the the <em>explicit</em> winner they can still be the
	 * <em>implicit</em> winners of a game because the other team lost
	 * <em>explicitly</em>.
	 * 
	 * @return <code>true</code> if the team has either won or lost.
	 */
	public boolean isOut() {
		return hasWon() || hasLost();
	}

	/**
	 * Determine if the team has (explicitly) lost the game.
	 * 
	 * @return <code>true</code> if the team has lost.
	 */
	public boolean hasLost() {
		return getScore() < -500;
	}

	/**
	 * Determine if the team has (explicitly) won the game.
	 * 
	 * @return <code>true</code> if the team has won.
	 */
	public boolean hasWon() {
		return getScore() > 500;
	}
}
